﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApp.App.Models.DAL.Cms
{
    public class Site
    {
        public class __GetSite_sites__:NRapid.Struct
		{
			public System.Int64 id;
			public System.String name;
			public System.Int64? channel_id;
			public System.String subdomain_name;
			public System.String title;
			public System.String company;
			public System.String address;
			public System.String tel;
			public System.String fax;
			public System.String email;
			public System.String copyright;
			public System.String seo_folder;
			public System.String seo_title;
			public System.String seo_keyword;
			public System.String seo_description;
			public System.Int16? is_default;
			#region 写Json字符串
			public override void WriteJson(System.IO.TextWriter tw)
			{
				tw.Write("{");
						tw.Write("\"id\":");
						tw.Write(id.ToString());
						tw.Write(",");
						tw.Write("\"name\":");
						if(name==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(name);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"channel_id\":");
						tw.Write(channel_id==null?"null" : channel_id.ToString());
						tw.Write(",");
						tw.Write("\"subdomain_name\":");
						if(subdomain_name==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(subdomain_name);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"title\":");
						if(title==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(title);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"company\":");
						if(company==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(company);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"address\":");
						if(address==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(address);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"tel\":");
						if(tel==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(tel);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"fax\":");
						if(fax==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(fax);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"email\":");
						if(email==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(email);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"copyright\":");
						if(copyright==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(copyright);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"seo_folder\":");
						if(seo_folder==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(seo_folder);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"seo_title\":");
						if(seo_title==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(seo_title);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"seo_keyword\":");
						if(seo_keyword==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(seo_keyword);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"seo_description\":");
						if(seo_description==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(seo_description);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"is_default\":");
						tw.Write(is_default==null?"null" : is_default.ToString());
				tw.Write("}");
			}
			#endregion
		}
		public NRapid.List<Models.Entity.Common.site> GetSite()
        {
            
            var con = new System.Data.SQLite.SQLiteConnection(NRapid.Config.ConfigurationManager.ConnectionStrings["Common"].ConnectionString);
			con.Open();
            #region	var defaultSiteId; 选取首行首列的值
			var __GetSite_defaultSiteId_command__ = new System.Data.SQLite.SQLiteCommand("select id from site where is_default!=0", con);
			var defaultSiteId = __GetSite_defaultSiteId_command__.ExecuteScalar().ToInt32();
			__GetSite_defaultSiteId_command__.Dispose();
			#endregion
			
            defaultSiteId = 1;
            #region	var sites;选取所有记录
			NRapid.List<Models.Entity.Common.site> sites=new NRapid.List<Models.Entity.Common.site>();
			var __GetSite_sites_command__ = new System.Data.SQLite.SQLiteCommand("select * from site where is_default!=0", con);
			var __GetSite_sites_reader__= __GetSite_sites_command__.ExecuteReader();
			if (__GetSite_sites_reader__.HasRows)
			{
				while (__GetSite_sites_reader__.Read())
				{
					var __GetSite_sites_temp__ = new Models.Entity.Common.site();
					__GetSite_sites_temp__.id = __GetSite_sites_reader__.GetInt64(0);
					__GetSite_sites_temp__.name =__GetSite_sites_reader__.IsDBNull(1)?null: __GetSite_sites_reader__.GetString(1);
					if(!__GetSite_sites_reader__.IsDBNull(2)){__GetSite_sites_temp__.channel_id = __GetSite_sites_reader__.GetInt64(2);}
					__GetSite_sites_temp__.subdomain_name =__GetSite_sites_reader__.IsDBNull(3)?null: __GetSite_sites_reader__.GetString(3);
					__GetSite_sites_temp__.title =__GetSite_sites_reader__.IsDBNull(4)?null: __GetSite_sites_reader__.GetString(4);
					__GetSite_sites_temp__.company =__GetSite_sites_reader__.IsDBNull(5)?null: __GetSite_sites_reader__.GetString(5);
					__GetSite_sites_temp__.address =__GetSite_sites_reader__.IsDBNull(6)?null: __GetSite_sites_reader__.GetString(6);
					__GetSite_sites_temp__.tel =__GetSite_sites_reader__.IsDBNull(7)?null: __GetSite_sites_reader__.GetString(7);
					__GetSite_sites_temp__.fax =__GetSite_sites_reader__.IsDBNull(8)?null: __GetSite_sites_reader__.GetString(8);
					__GetSite_sites_temp__.email =__GetSite_sites_reader__.IsDBNull(9)?null: __GetSite_sites_reader__.GetString(9);
					__GetSite_sites_temp__.copyright =__GetSite_sites_reader__.IsDBNull(10)?null: __GetSite_sites_reader__.GetString(10);
					__GetSite_sites_temp__.seo_folder =__GetSite_sites_reader__.IsDBNull(11)?null: __GetSite_sites_reader__.GetString(11);
					__GetSite_sites_temp__.seo_title =__GetSite_sites_reader__.IsDBNull(12)?null: __GetSite_sites_reader__.GetString(12);
					__GetSite_sites_temp__.seo_keyword =__GetSite_sites_reader__.IsDBNull(13)?null: __GetSite_sites_reader__.GetString(13);
					__GetSite_sites_temp__.seo_description =__GetSite_sites_reader__.IsDBNull(14)?null: __GetSite_sites_reader__.GetString(14);
					if(!__GetSite_sites_reader__.IsDBNull(15)){__GetSite_sites_temp__.is_default = __GetSite_sites_reader__.GetInt16(15);}
					sites.Add(__GetSite_sites_temp__);
				}
			}
			__GetSite_sites_reader__.Dispose();
			__GetSite_sites_command__.Dispose();
			#endregion
			
            con.Close();
            return sites;
        }
    }
}        